<template>
  <div />
</template>
<script>
import { resetRouter } from 'src/router';
import { openURL } from 'quasar';

export default {
  components: {},
  props: {},
  data() {
    return {
      subSystem: '',
      subSystemList: [],
      selectUser: {},
      password: '',
      confirmpassword: '',
      selective: {},
    };
  },
  watch: {
  },
  computed: {
    welcomeInfo() {
      return `欢迎您，${this.$store.state.User.info.realname}`;
    },
    isValid() {
      return this.confirmpassword === this.password;
    },
  },
  methods: {
    backstage() {
      window.location.href = '/#/sys/home';
    },
    moduleUrl(sub) {
      const { routes } = this.$store.state.Rule;
      routes.forEach((route) => {
        if (route.subSystem === sub.id) {
          // 内部还是外部
          if (route.meta.internalOrExternal) {
            openURL(route.fullPath);
          } else {
            this.subSystem = sub.id;
            this.renderSubSystemMenu();
            const to = route.children[0];
            this.$store.commit('Rule/clearRouteTabs');
            this.$store.commit('Rule/addRouteTabs', { name: to.meta.title, path: to.path, fullPath: to.fullPath });
            this.$router.push(to.fullPath);
          }
        }
      });
    },
    updPsw() {
      this.selectUser = this.$store.state.User.info;
      this.password = '';
      this.confirmpassword = '';
      this.$refs.changePassWord.show();
    },
    changePassWord() {
      this.$axios.put('/sys/user/changePasswordByUser', {
        confirmpassword: this.confirmpassword,
        password: this.password,
        username: this.selectUser.username,
      }).then((r) => {
        this.$info(r.message);
        this.$refs.changePassWord.hide();
        this.out();
      });
    },
    renderSubSystemMenu() {
      const { routes } = this.$store.state.Rule;
      // 需要根据当前已有菜单来控制到底有哪些子系统
      this.subSystemList = this.subSystemList.filter((subSystem) => routes.some((route) => route.subSystem === subSystem.id));
      localStorage.subSystemList = JSON.stringify(this.subSystemList);
    },
    out() {
      this.$axios.get('/sys/logout').then(() => {
        this.$store.commit('User/clear');
        this.$store.commit('Rule/clear');
      }).finally(() => {
        resetRouter();
        window.location.replace('#/login');
      });
    },
  },
  created() {
    this.$axios.get('/sys/subsystem/list?pageSize=20').then((r) => {
      this.subSystemList = r.result.records;
      this.renderSubSystemMenu();
      this.moduleUrl(this.subSystemList[0]);
    });
  },
  mounted() {

  },
};
</script>
<style lang="stylus">
.mod-con
  width: 70%;
  height: 245px;
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  margin: 15% auto;

.mod-con-grey
  width: 70%;
  height: 245px;
  border-radius: 8px;
  margin: 15% auto;
  overflow: hidden;

.mod-con:hover
  opacity: .9;
  box-shadow: 0 0 40px rgba(1, 1, 1, .3);
  transform: scale(1.1, 1.1);
  transition: all .3s;

.tit-mod
  color: #fff;
  font-size: 18px;
  text-shadow: 1px 1px 3px rgba(1, 1, 1, .5);
  padding-left: 8px;

.label-bor
  font-weight 700;
  width 90%;
  height 85%;
  border 1px solid rgba(255, 255, 255, 0);
  cursor pointer;

.label-bor-grey
  width: 90%;
  height: 85%;

.mod-con:hover .label-bor
  border: 1px solid rgba(255, 255, 255, .5);
  transition: all 1s;

.flex-2c
  display: flex;
  justify-content: center;
  align-items: center;

</style>
